#include "TextWindow.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

TextWindow::TextWindow(int length)
{
	this->file_position = 0;
	this->length = length;
	this->substring = (char *)malloc(sizeof(char) * length + 1);
	memset(this->substring, '\0', sizeof(char)*length+1);
}

TextWindow::~TextWindow(void)
{
	free(this->substring);
}

char TextWindow::tail() {
	if(this->length > 0)
//z		return substring[length];
		return substring[length-1];
	else
		return 0;
}
char TextWindow::head() {
	if(this->length > 0)
		return substring[0];
	else
		return 0;
}

void TextWindow::print() {
	printf("<%d>: \"%s\"\n", this->file_position, this->substring);
}